<?php
date_default_timezone_set('PRC');
require_once dirname(__FILE__) . './models/wanted.php';

if( isset($_REQUEST["action"]) ){
	if( $_REQUEST["action"] == "submit" ){
		$post = new wanted();
		$post->date = time();
		$post->title =  $_REQUEST["title"];
		$post->content = $_REQUEST["content"];
		$post->save();
	}
	
	if( $_REQUEST["action"] == "delete" ){
		$post = wanted::find($_REQUEST["id"]);
		$post->delete();
	}	
}

?>

<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<?php header("Content-type: text/html; charset=utf-8"); ?>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="libs\bootstrap-3.0.3-dist\dist\css\bootstrap.min.css">
	<style>
	.cardpanel .popover {
		position: relative;
		display: block;
		float: left;
		width: 260px;
		height:140px;
		margin: 10px; 
	}
	.cardpanel .popover-title{
		font-weight: bold;
	}
	.cardpanel .popover-content p{
		
	}
	</style>
  </head>
  <body>
	<div class="container"> 
		<a href="index.php">进度</a>
		<a href="wanted.php">需求</a>
		<a href="keyword.php">关键字</a>
	</div>
    <div class="container" style="padding:15px;">
		<form action="wanted.php" method="post">
			<div class="form-group">
				<input class="form-control" name="title" placeholder="输入需求标题"></textarea>
			</div>
			
			<div class="form-group">
				<textarea class="form-control" rows="3" name="content" placeholder="输入需求内容"></textarea>
			</div>
			<input type="submit" value="submit" class="btn btn-primary pull-right">
			<input type="hidden" name="action" value="submit">
		</form>
	</div>
	
	<div class="container cardpanel ">
		<?php
		$wanteds = wanted::find('all');
		foreach ($wanteds as $key=>$node) { 
			$fmt_date = date('Y-m-d H:i:s', $node->date);
			$title = $node->title;
			$content = $node->content;
			$id = $node->id;
		?>
		<div class="popover">
			<?php ?>
			<a href="wanted.php?action=finish&id=<?php echo $id; ?>">
				<span class="glyphicon glyphicon-ok-circle"></span>
			</a>
			<a href="wanted.php?action=delete&id=<?php echo $id; ?>">
				<button type="button" class="close" aria-hidden="true" style="margin:0 3px;">&times;</button>
			</a>
			<h3 class="popover-title"><?php echo $title;?></h3>
			<div class="popover-content text-overflow">
			  <p><?php echo $content;?></p>
			</div>
		</div>
		  
		<?php } ?>
		<div class="clearfix"></div>
	</div>
	
    <script src="http://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
    <script src="libs\bootstrap-3.0.3-dist\dist\js\bootstrap.min.js"></script>
  </body>
</html>



